package com.yang.core;

import java.util.ArrayList;

public class TestResult {
    private String lable;
    private int count;
    private int error;
    private long startTime;
    private long endTime;
    private ArrayList<Integer> elapsed = new ArrayList<Integer>();
    private float receivedBytes;
    private float sentBytes;

    public TestResult() {
    }

    public void update(HttpSample httpSample) {
        setLable(httpSample.getLabel());
        addCount();
        addLatency(httpSample.getElapsed());
        addError(httpSample.getError());
        setStartTime(httpSample.getTimeStamp());
        setEndTime(httpSample.getEndTimeStamp());
        addReceivedBytes(httpSample.getReceivedBytes());
        addSentBytes(httpSample.getSentBytes());
    }

    public void addCount() {
        this.count++;
    }

    public void addLatency(int latency) {
        this.elapsed.add(latency);
    }

    public void addSentBytes(int bytes) {
        this.sentBytes += bytes;
    }

    public void addReceivedBytes(int bytes) {
        this.receivedBytes += bytes;
    }

    public void addError(String error) {
        if (error.equals("false")) {
            this.error++;
        }
    }

    public String getLable() {
        return lable;
    }

    public void setLable(String lable) {
        if (this.lable == null) {
            this.lable = lable;
        }

    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getError() {
        return error;
    }

    public void setError(int error) {
        this.error = error;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        if (startTime < this.startTime || this.startTime == 0) {
            this.startTime = startTime;
        }
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        if (endTime > this.endTime || this.endTime == 0) {
            this.endTime = endTime;
        }
    }

    public ArrayList<Integer> getElapsed() {
        return elapsed;
    }

    public void setElapsed(ArrayList<Integer> elapsed) {
        this.elapsed = elapsed;
    }

    public float getReceivedBytes() {
        return receivedBytes;
    }

    public void setReceivedBytes(float receivedBytes) {
        this.receivedBytes = receivedBytes;
    }

    public float getSentBytes() {
        return sentBytes;
    }

    public void setSentBytes(float sentBytes) {
        this.sentBytes = sentBytes;
    }
}
